package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.CoursesInfo;
import com.example.computer_exam_training_sys.entity.UserStudyPlansInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserStudyPlansMapper {

    //全内容查取
    @Select("SELECT * from user_study_plans ")
    public List<UserStudyPlansInfo> findall();

    //单个用户全内容查取
    @Select("SELECT * from user_study_plans where user_id= #{userId}")
    public List<UserStudyPlansInfo> finduserAll(Integer userId);

    //按计划id查取
    @Select("SELECT * from user_study_plans where plan_id= #{planId}")
    public UserStudyPlansInfo findplanById(Integer planId);

    //更新进度
    @Update("UPDATE user_study_plans\n" +
            "    SET current_progress = current_progress + #{addProgress}, update_time = NOW()\n" +
            "    WHERE plan_id = #{planId}")
    public int updateplanProgress(@Param("planId") Integer planId, @Param("addProgress") Integer addProgress);

    //更新状态
    @Update("UPDATE user_study_plans\n" +
            "    SET status = #{status}, update_time = NOW()\n" +
            "    WHERE plan_id = #{planId}")
    public int updateplanStatus(@Param("planId") Integer planId, @Param("status")Integer status);

    //删除计划
    @Delete("DELETE FROM user_study_plans WHERE plan_id= #{planId}")
    public int deleteplanById(Integer planId);

    //创建计划
    @Insert("INSERT INTO user_study_plans " +
            "(user_id, plan_name, start_date, end_date, daily_target, current_progress, status, create_time) " +
            "VALUES (#{userId}, #{planName}, #{startDate}, #{endDate}, #{dailyTarget}, #{currentProgress}, #{status}, NOW())")
    public int insert(UserStudyPlansInfo userStudyPlansInfo);






}
